package cn.iocoder.yudao.module.dt.controller.admin.activitysumbit;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.dt.controller.admin.activitysumbit.vo.*;
import cn.iocoder.yudao.module.dt.dal.dataobject.activitysumbit.ActivitySumbitDO;
import cn.iocoder.yudao.module.dt.convert.activitysumbit.ActivitySumbitConvert;
import cn.iocoder.yudao.module.dt.service.activitysumbit.ActivitySumbitService;

@Api(tags = "管理后台 - 活动提交")
@RestController
@RequestMapping("/dt/activity-sumbit")
@Validated
public class ActivitySumbitController {

    @Resource
    private ActivitySumbitService activitySumbitService;

    @PostMapping("/create")
    @ApiOperation("创建活动提交")
    @PreAuthorize("@ss.hasPermission('dt:activity-sumbit:create')")
    public CommonResult<Integer> createActivitySumbit(@Valid @RequestBody ActivitySumbitCreateReqVO createReqVO) {
        return success(activitySumbitService.createActivitySumbit(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新活动提交")
    @PreAuthorize("@ss.hasPermission('dt:activity-sumbit:update')")
    public CommonResult<Boolean> updateActivitySumbit(@Valid @RequestBody ActivitySumbitUpdateReqVO updateReqVO) {
        activitySumbitService.updateActivitySumbit(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除活动提交")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('dt:activity-sumbit:delete')")
    public CommonResult<Boolean> deleteActivitySumbit(@RequestParam("id") Integer id) {
        activitySumbitService.deleteActivitySumbit(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得活动提交")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
    @PreAuthorize("@ss.hasPermission('dt:activity-sumbit:query')")
    public CommonResult<ActivitySumbitRespVO> getActivitySumbit(@RequestParam("id") Integer id) {
        ActivitySumbitDO activitySumbit = activitySumbitService.getActivitySumbit(id);
        return success(ActivitySumbitConvert.INSTANCE.convert(activitySumbit));
    }

    @GetMapping("/list")
    @ApiOperation("获得活动提交列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('dt:activity-sumbit:query')")
    public CommonResult<List<ActivitySumbitRespVO>> getActivitySumbitList(@RequestParam("ids") Collection<Integer> ids) {
        List<ActivitySumbitDO> list = activitySumbitService.getActivitySumbitList(ids);
        return success(ActivitySumbitConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得活动提交分页")
    @PreAuthorize("@ss.hasPermission('dt:activity-sumbit:query')")
    public CommonResult<PageResult<ActivitySumbitRespVO>> getActivitySumbitPage(@Valid ActivitySumbitPageReqVO pageVO) {
        PageResult<ActivitySumbitDO> pageResult = activitySumbitService.getActivitySumbitPage(pageVO);
        return success(ActivitySumbitConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出活动提交 Excel")
    @PreAuthorize("@ss.hasPermission('dt:activity-sumbit:export')")
    @OperateLog(type = EXPORT)
    public void exportActivitySumbitExcel(@Valid ActivitySumbitExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ActivitySumbitDO> list = activitySumbitService.getActivitySumbitList(exportReqVO);
        // 导出 Excel
        List<ActivitySumbitExcelVO> datas = ActivitySumbitConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "活动提交.xls", "数据", ActivitySumbitExcelVO.class, datas);
    }

}
